package com.itheima.controller;

import com.itheima.entity.ShoppingCart;
import com.itheima.service.IShoppingCartService;
import com.itheima.util.Result;
import com.itheima.util.UserHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 老师好我是郁同学
 * @date  2022/10/10
 **/
@Slf4j
@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private IShoppingCartService shoppingCartService;

    @PostMapping("/add")
    public Result add(@RequestBody ShoppingCart shoppingCart){
        //
        shoppingCart.setUserId(UserHolder.getUserId());
        return shoppingCartService.add(shoppingCart);
    }

    @DeleteMapping("/clean")
    public Result clean(){
        return shoppingCartService.clean();
    }

    @PostMapping("/sub")
    public Result sub(@RequestBody ShoppingCart shoppingCart){
        return shoppingCartService.sub(shoppingCart);
    }

    @GetMapping("/list")
    public Result shoppingCartList(){
        return shoppingCartService.shoppingCartList();
    }

}
